package com.itheima.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/*
udp接收端
 */
public class JieshouClient {

    public static void main(String[] args) throws IOException {
        //创建接受对象
        DatagramSocket ds = new DatagramSocket(8888);
        //创建数据对象
        byte[] bytes = new byte[1024 * 64];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);

        // 接受
        ds.receive(dp);

        //查看数据
        //byte[] data = dp.getData();
        int length = dp.getLength();
        String s = new String(bytes, 0, length);
        System.out.println(s);
        // 释放资源
        ds.close();

    }
}
